package jianzhi;

import niuke.ListNode;

/**
 * description:
 * author:zt
 * date:2021-10-26
 */
//给定单向链表的头指针和一个要删除的节点的值，定义一个函数删除该节点。
//
//返回删除后的链表的头节点。
public class jianzhi18 {
    public ListNode deleteNode(ListNode head, int val) {
        if (head == null) return head;
        ListNode cur = head, dum = new ListNode();
        ListNode pre = dum;
        pre.next = cur;
        while (cur != null) {
            if (cur.val == val){
                pre.next = cur.next;
                break;
            }
            cur = cur.next;
            pre = pre.next;
        }
        return dum.next;
    }
}
